using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WP.Commons;
namespace WP.Modules
{
    public partial class frmInput : BaseQryRpt
    {
        private bool m_bHaveReturnValue = true;
        private bool mblnIsMultiLine = false;
        public frmInput()
        {
            InitializeComponent();
        }

        private string m_strCheckEmpty = "", m_strCheckExist = "", m_strCheckRange = "";
        public string InputData(string prompt, string caption,string strDefautValue, bool IsMultLine )
        {
            mblnIsMultiLine = IsMultLine;
            return InputData(prompt, caption, strDefautValue, "", "", "", false);
        }
        public string InputData(string prompt, string caption, string strDefautValue)
        {
            return InputData(prompt, caption, strDefautValue, "", "", "", false);
        }
        public string InputData(string prompt, string caption, string strDefautValue, string CheckEmpty, string CheckExist, string CheckRange)
        {
            return InputData(prompt, caption, strDefautValue, CheckEmpty, CheckExist, CheckRange, false);
        }
        public string InputData(string prompt, string caption, string strDefautValue, string CheckEmpty, string CheckExist, string CheckRange, bool bDisplayCancelButton)
        {
            string strReturn = string.Empty;
            this.Text =( caption!="" ? caption :this.Text);
            if (bDisplayCancelButton) this.btnCancel.Visible = true;
            if (prompt.TrimEnd() != "")
                this.lblPrompt.Text = prompt + ":";
            else
                this.lblPrompt.Text = "";
            this.txtBox.Text = strDefautValue;
            m_strCheckEmpty = CheckEmpty;
            m_strCheckExist = CheckExist;
            m_strCheckRange = CheckRange;


            if (mblnIsMultiLine) 
            {
                txtBox.Multiline = true;
                this.Size = new Size(400, 300); 
            }

            this.ShowDialog();
            this.Close();
            if (m_bHaveReturnValue)
                strReturn = this.txtBox.Text;
            else
                strReturn = "%NONE%";

            return strReturn;
         }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string strErrMsg = "";
            if (!RuleBase.CheckEmpty(txtBox.Text.Trim(), m_strCheckEmpty, ref strErrMsg))
            {
                MsgBoxEx.Show(strErrMsg,SysVar.WarnTitle);
                return;
            }
            if (!RuleBase.CheckRange(txtBox.Text.Trim(),m_strCheckRange , ref strErrMsg))
            {
                MsgBoxEx.Show(strErrMsg, SysVar.WarnTitle);
                return;
            }
            if (!RuleBase.CheckFieldValueExist (txtBox.Text.Trim(),m_strCheckExist , ref strErrMsg))
            {
                MsgBoxEx.Show(strErrMsg, SysVar.WarnTitle);
                return;
            }

            this.Hide (); 
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            m_bHaveReturnValue = false;
            this.Hide();
        }

        private void frmInput_Load(object sender, EventArgs e)
        {
            this.txtBox.Focus();
        }

    }
}